package com.google.gac.masai.getit;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.preference.DialogPreference;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.util.AttributeSet;
import android.widget.EditText;

public class SpecRule extends DialogPreference {
	
	Dialog mDialog;
	Context mContext;
	String test = "hello";
	private SharedPreferences mPreferences;
	
	

	public SpecRule(Context context, AttributeSet attr) {
		super(context, attr);
		mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
	}
	
	public void onClick (DialogInterface dialog, int which) {
		if (which == DialogInterface.BUTTON_POSITIVE) {
			String hello = this.getFragment();
			this.setTitle(hello);

			PreferenceScreen wrapper = PrefsFragment.wrapper;
			wrapper.removePreference(this);
			
			int numRules = mPreferences.getInt("NumSpecRules", 0);
			
			String thisKey = getKey();
			
			SharedPreferences.Editor edit = mPreferences.edit();
	        edit.putInt("NumSpecRules", --numRules);
	        edit.putBoolean(thisKey, false);
			edit.commit();
		}
		/*
		mDialog = new Dialog(mContext);
		
		mDialog.setContentView(R.layout.popupwindow);
		mDialog.setTitle("Login to your DropBox account");
		
		EditText login = (EditText) mDialog.findViewById(R.id.login);
		EditText password = (EditText) mDialog.findViewById(R.id.password);
		
		Button loginButton = (Button) mDialog.findViewById(R.id.LoginButton);
		Button cancelButton = (Button) mDialog.findViewById(R.id.CancelLoginButton);
		
		
		
		mDialog.show(); 
		
		cancelButton.setOnClickListener(new OnClickListener() {
			
			//@Override
			public void onClick(View v) {
				mDialog.dismiss(); // cancel dialogs
			}
		}); 
		
		loginButton.setOnClickListener(new OnClickListener() {
			
			//@Override
			public void onClick(View v) {
				// Login to dropbox
				//showToast("Attempting Dropbox login");
				
				// Get username and password entered
				EditText login = (EditText) mDialog.findViewById(R.id.login);
				EditText password = (EditText) mDialog.findViewById(R.id.password);
				
				
				// To be done later : basic user-input checking here
				
		        
		        mDialog.dismiss(); // close dialogs
			}
		
	});
	*/
		
	}
	
}
